<template>
  <div class="photoinfo-container">
    <h3>{{ photoinfo.title }}</h3>
    <p class="subtitle">
      <span>发表时间：{{ photoinfo.add_time | dateFormat }}</span>
      <span>点击：{{ photoinfo.click }}次</span>
    </p>
    <hr>
    <!-- 缩略图区域 -->
    <vue-preview
      :list="list"
      :thumbImageStyle="{width: '100px', height: '100px', margin: '10px', 
      'object-fit':'cover', 'box-shadow':'0 0 8px #999 '}"
      :previewBoxStyle="{border: '1px solid #eee'}"
      :tapToClose="true"
    />
    <!-- 图片内容区域 -->
    <div class="content" v-html="photoinfo.content"></div>
    <!-- 评论子组件,放置一个现成的评论子组件 -->
    <comment :obj_id="id"></comment>
  </div>
</template>
<script>
import { Toast } from "mint-ui";
import comment from "../../subcomponents/comment.vue";
export default {
  data() {
    return {
      id: this.$route.params.id,
      photoinfo: {}, // 存放获取到的photoinfo对象
      list: []
    };
  },
  created() {
    this.getimageinfo();
    this.getthumbimages();
  },
  methods: {
    // 获取图片详情
    getimageinfo() {
      this.$http.get("api/getimageinfo/" + this.id + "/").then(result => {
        if (result.data.status === 0) {
          this.photoinfo = result.data.message[0];
        } else if (result.data.status === -1) {
          return Toast("错误:图片对象不存在!");
        }
      });
    },
    // 获取缩略图
    getthumbimages() {
      this.$http.get("api/getthumbimages/" + this.id + "/").then(result => {
        if (result.data.status === 0) {
          // 遍历数组,添加w和h属性
          result.data.message.forEach(element => {
            element.w = 600;
            element.h = 400;
          });
          this.list = result.data.message;
        }
      });
    }
  },
  components: {
    comment
  }
};
</script>
<style lang="scss" scoped>
.photoinfo-container {
  padding: 3px;
  h3 {
    color: #26a2ff;
    font-size: 15px;
    text-align: center;
    margin: 15px 0;
  }
  .subtitle {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
  }
  .thumbImg {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .content {
    font-size: 13px;
    line-height: 30px;
  }
}
</style>
